import request, { PageQuery, PageResponse } from './request';

// 权限实体
export interface SysPermission {
  id?: number;
  permissionName: string;
  permissionCode: string;
  permissionType: number; // 1-菜单，2-按钮，3-API
  description: string;
  status: number; // 0-禁用，1-启用
  createTime?: string;
  updateTime?: string;
}

// 权限管理API
export const permissionApi = {
  // 分页查询权限列表
  pagePermissions: (params: PageQuery): Promise<PageResponse<SysPermission>> => {
    return request.get('/system/permission/page', { params });
  },

  // 查询所有权限
  listPermissions: (): Promise<SysPermission[]> => {
    return request.get('/system/permission/list');
  },

  // 根据ID查询权限
  getPermission: (id: number): Promise<SysPermission> => {
    return request.get(`/system/permission/${id}`);
  },

  // 创建权限
  createPermission: (data: SysPermission): Promise<string> => {
    return request.post('/system/permission', data);
  },

  // 更新权限
  updatePermission: (data: SysPermission): Promise<string> => {
    return request.put('/system/permission', data);
  },

  // 删除权限
  deletePermission: (id: number): Promise<string> => {
    return request.delete(`/system/permission/${id}`);
  },
};